*********************************************************
* Do-file for the analyses contained in the manuscript:
* Germany’s decision to phase out coal by 2038 lags  //
* behind citizens‘ timing preferences
* Author: Adrian Rinscheid
*********************************************************

*Analyses conducted with Stata 14.2
*Plotting with R

import delimited "/Users/adrianrinscheid/dataverse/coalphaseout.csv", delimiter(";") varnames(1) case(preserve) encoding(ISO-8859-1)clear
***

*renaming choice experiment attributes
rename Attr1_recode attime
rename Attr2_recode atlostjobs
rename Attr3_recode atmeasures
rename Attr4_recode atnewjobs
rename Attr5_recode atcost

*preparation of rating outcome
gen rating = .
replace rating = 0 if rating_raw == 1
replace rating = 1/6 if rating_raw == 2
replace rating = 2/6 if rating_raw == 3
replace rating = 3/6 if rating_raw == 4
replace rating = 4/6 if rating_raw == 5
replace rating = 5/6 if rating_raw == 6
replace rating = 1 if rating_raw == 7

*binary rating outcome
gen brating = 0
replace brating = 1 if rating >.5
tab rating brating

***

*helper program to grab estimates and SEs from models 
//credits to Hainmueller, Hopkins & Yamamoto (2013: Causal Inference in Conjoint Analysis: Understanding Multidimensional Choices via Stated Preference Experiments)
capture program drop jadjust
program def jadjust
capture matrix drop resmat
* get coefficients and SEs
mat    coef = e(b)
mat    varr = vecdiag(e(V))
matmap varr se , m(sqrt(@))
mat    coef = coef' , se'
scalar R = rowsof(coef)-1
mat    coef = coef[1..R,1..2]
* eliminate interactions terms
local namess : rownames coef
 foreach el of local namess {
   local include = regexm("`el'", "#")
   if "`include'" != "1" {
                    matrix getthis = coef["`el'",1..2]
                    matrix resmat = nullmat(resmat) \ getthis
            }
 }
end

***

*results in the paper are based on cleaned samples; i.e. respondents who failed the attention check are excluded.
*attention check (D0)
*Ein kurzer Aufmerksamkeitstest: bitte wählen Sie das Wort „Energie“ aus der Liste aus.
*1. Wind  |  2. Stromleitung  |  3. Weder noch
*4. Überhaupt nicht  |  5. Energie  |  6. Jürgen Klopp
*D0==5 is correct

*samples
*variable "hidsample" allows differentiating samples
*1 = Deutschland  |  2 = Rheinland  |  3 = Lausitz

***

*Figure 2 | Average effects of policy attributes on respondents’ preference for a coal phase-out.

*dichotomized rating outcome (only GER)

*note: baseline of timing attribute: 2040.
global mod =  "ib3.attime i.atcost i.atlostjobs i.atnewjobs i.atmeasures"
global ses =  "cl(record)"
reg brating $mod , $ses , if hidsample ==1 & D0==5
jadjust
matlist resmat
* save for plotting in R
mat2txt , matrix(resmat) saving("coal_brating40.txt")  replace
capture matrix drop resmat
*the results are also shown in Table S1 ("Model 1").

***

*Figure 3 | Average effects of timing attribute on respondents’ preference 
//for a coal-phase out by party identification and perceived scientific consensus.

*Fig. 3a
*subgroup analyses for parties (only GER)

*party identification (D8a)
*original qustion wording:
*a) Welcher Partei neigen Sie zu? //
*1. SPD  |  2. CDU  |  3. CSU
*4. FDP  |  5. Bündnis 90/Die Grünen  |  6. Die Linke
*7. AFD  |  8. Eine andere Partei, und zwar _______

qui reg brating $mod , $ses , if hidsample ==1 & D8a ==5 & D0==5
parmest, saving(coal_parties140, replace)
qui reg brating $mod , $ses , if hidsample ==1 & D8a ==1 & D0==5
parmest, saving(coal_parties240, replace)
qui reg brating $mod , $ses , if hidsample ==1 & D8a ==6 & D0==5
parmest, saving(coal_parties340, replace)
qui reg brating $mod , $ses , if hidsample ==1 & D8a ==2 & D0==5
parmest, saving(coal_parties440, replace)
qui reg brating $mod , $ses , if hidsample ==1 & D8a ==3 & D0==5
parmest, saving(coal_parties540, replace)
qui reg brating $mod , $ses , if hidsample ==1 & D8a ==4 & D0==5
parmest, saving(coal_parties640, replace)
qui reg brating $mod , $ses , if hidsample ==1 & D8a ==7 & D0==5
parmest, saving(coal_parties740, replace)

*Fig. 3b
*subgroup analyses for perceived scientific consensus (only GER)

*perceived scientific consensus (D4)
*original qustion wording:
*Was denken Sie: Wie hoch ist der Anteil der Klimawissenschaftler weltweit, die davon ausgehen, dass die 
//Erhöhung der Kohlenstoffdioxid (CO2)-Konzentration in der Atomsphäre seit der Mitte des 20. Jahrhunderts in 
//erster Linie auf menschliche Aktivitäten zurückzuführen ist? //
*Bitte wählen Sie einen Prozentsatz mit dem Schieberegler.

. gen consensus =0
. replace consensus =1 if D4 >49
. replace consensus =2 if D4 >69
. replace consensus =3 if D4 >89
. catplot consensus
qui reg brating $mod , $ses , if hidsample ==1 & consensus==0 & D0==5
parmest, saving(coal_consensus1, replace)
qui reg brating $mod , $ses , if hidsample ==1 & consensus==1 & D0==5
parmest, saving(coal_consensus2, replace)
qui reg brating $mod , $ses , if hidsample ==1 & consensus==2 & D0==5
parmest, saving(coal_consensus3, replace)
qui reg brating $mod , $ses , if hidsample ==1 & consensus==3 & D0==5
parmest, saving(coal_consensus4, replace)

***

*Figure 4 | Average effects of timing attribute on respondents’ preference 
//for a coal-phase out in Rhineland and Lusatia.

*working in coal industry (D5) 
*Arbeiten Sie im Braunkohletagebau oder in einem Kohlekraftwerk, oder haben Sie in der Vergangenheit im 
//Braunkohletagebau oder in einem Kohlekraftwerk gearbeitet?
*1. Ja  |  2. Nein

*having acquaintances in coal industry (D6)
*Kennen Sie persönlich eine Person, die im Braunkohletagebau oder in einem Kohlekraftwerk arbeitet oder 
//einmal gearbeitet hat?
*1. Ja  |  2. Nein

*note: baseline of timing attribute still 2040.
global mod =  "ib3.attime i.atcost i.atlostjobs i.atnewjobs i.atmeasures"
global ses =  "cl(record)"

*Fig. 4a: Rhineland
*unconditional effects
qui reg brating $mod , $ses , if hidsample ==2 & D0==5
parmest, saving(coal_brating240, replace)
*working in coal industry or having acquaintances who work in coal industry
qui reg brating $mod , $ses , if hidsample ==2 & D0==5 & (D5==1 | D6==1)
parmest, saving(coal_worksknows240, replace)
*NOT working in coal industry, no acquaintances
qui reg brating $mod , $ses , if hidsample ==2 & D5!=1 & D6!=1 & D0==5
parmest, saving(coal_notworksknows240, replace)
*the results are also shown in Table S4.

*Fig. 4a: Lusatia
*unconditional effects
qui reg brating $mod , $ses , if hidsample ==3 & D0==5
parmest, saving(coal_brating340, replace)
*working in coal industry or having acquaintances who work in coal industry
qui reg brating $mod , $ses , if hidsample ==3 & D0==5 & (D5==1 | D6==1)
parmest, saving(coal_worksknows340, replace)
*NOT working in coal industry, no acquaintances
qui reg brating $mod , $ses , if hidsample ==3 & D5!=1 & D6!=1 & D0==5
parmest, saving(coal_notworksknows340, replace)
*the results are also shown in Table S6.

***

*robustness checks: redo all analyses, but include inattentive respondents

*dichotomized rating outcome (only GER)
*see Table S1 ("Model 2").
global mod =  "ib3.attime i.atcost i.atlostjobs i.atnewjobs i.atmeasures"
global ses =  "cl(record)"
reg brating $mod , $ses , if hidsample ==1
jadjust
matlist resmat
* save for plotting in R
mat2txt , matrix(resmat) saving("coal_brating40i.txt")  replace
capture matrix drop resmat

***

*subgroup analyses for parties (only GER)
*see Table S2a
reg brating $mod , $ses , if hidsample ==1 & D8a ==5
reg brating $mod , $ses , if hidsample ==1 & D8a ==1
reg brating $mod , $ses , if hidsample ==1 & D8a ==6
reg brating $mod , $ses , if hidsample ==1 & D8a ==2
reg brating $mod , $ses , if hidsample ==1 & D8a ==3
reg brating $mod , $ses , if hidsample ==1 & D8a ==4
reg brating $mod , $ses , if hidsample ==1 & D8a ==7

***

*subgroup analyses for perceived scientific consensus (only GER)
*see Table S3a
reg brating $mod , $ses , if hidsample ==1 & consensus==0 
reg brating $mod , $ses , if hidsample ==1 & consensus==1 
reg brating $mod , $ses , if hidsample ==1 & consensus==2 
reg brating $mod , $ses , if hidsample ==1 & consensus==3

***

*preferences for a coal phase-out in Rhineland
*see Table S4a
*unconditional effects
reg brating $mod , $ses , if hidsample ==2
*working in coal industry or having acquaintances who work in coal industry
reg brating $mod , $ses , if hidsample ==2 & (D5==1 | D6==1)
*NOT working in coal industry, no acquaintances
reg brating $mod , $ses , if hidsample ==2 & D5!=1 & D6!=1

***

*preferences for a coal phase-out in Lusatia
*see Table S5a
*unconditional effects
reg brating $mod , $ses , if hidsample ==3
*working in coal industry or having acquaintances who work in coal industry
reg brating $mod , $ses , if hidsample ==3 & (D5==1 | D6==1)
*NOT working in coal industry, no acquaintances
reg brating $mod , $ses , if hidsample ==3 & D5!=1 & D6!=1

***

*Supplementary Figures

*Supplementary Figure 1 | Implicit WTP for phasing out coal until 2025 or 2030, compared to 2038. 
*Estimation using continuous cost variable and based on pooled conjoint types 
//(with "types" referring to the 2 modes of presentation of the cost attribute; see methods section)
*wtp expressed in terms of overall costs for the economy that respondents would be willing to pay 
//(corresponds to the 2nd mode of cost framing in the experiment)

gen cost_cont=.

*1=0 2=250 3=500 4=750
replace cost_cont=0 if atcost==1 
replace cost_cont=250 if atcost==2 
replace cost_cont=500 if atcost==3 
replace cost_cont=750 if atcost==4 

*estimation for German sample
reg rating cost_cont ib3.attime i.atlostjobs i.atnewjobs i.atmeasures if hidsample ==1 & D0 ==5, cl(record)
parmest, saving(wtp_GER, replace)
*estimation for Rhineland sample // not shown in supplementary file
reg rating cost_cont ib3.attime i.atlostjobs i.atnewjobs i.atmeasures if hidsample ==2 & D0 ==5, cl(record)
parmest, saving(wtp_Rhine, replace)
*estimation for Lusatia sample // not shown in supplementary file
reg rating cost_cont ib3.attime i.atlostjobs i.atnewjobs i.atmeasures if hidsample ==3 & D0 ==5, cl(record)
parmest, saving(wtp_Lusatia, replace)

*Supplementary Figure 2: *Figure 2 | Average effects of policy attributes on respondents’ preference
//for a coal phase-out, based on the forced choice outcome

*note: baseline of timing attribute: 2040.
global mod =  "ib3.attime i.atcost i.atlostjobs i.atnewjobs i.atmeasures"
global ses =  "cl(record)"
reg selected $mod , $ses , if hidsample ==1 & D0==5
jadjust
matlist resmat
* save for plotting in R
mat2txt , matrix(resmat) saving("coal_selected40.txt")  replace
capture matrix drop resmat

*end

